import Taro, { Component } from '@tarojs/taro'
import PropsType from 'prop-types'
import classnames from 'classnames'
import { View, Text } from '@tarojs/components'
import { AtButton } from 'taro-ui'
import '../styles/logistics.scss'

export default class DLogistics extends Component {

    onHanldeFirst(e) {
        e.stopPropagation()
        this.props.onHanldeFirst && this.props.onHanldeFirst()
    }

    onHanldeSecode(e) {
        e.stopPropagation()
        this.props.onHanldeSecode && this.props.onHanldeSecode()
    }

    handleDetail() {
        this.props.handleDetail && this.props.handleDetail()
    }

    render() {
        const { 
            className,
            startplace, 
            endplace, 
            total, 
            time, 
            money, 
            summoney, 
            firstText, 
            secodeText
        } = this.props
        return (
            <View className={classnames("b_logistics", className)} onClick={this.handleDetail.bind(this)}>
                {
                    // list && list.map((item, i) => {
                        <View className='b_logistics__item'>
                            <View className='b_logistics__item_startplace'>
                                <Text className='b_logistics__title'>起发地址</Text>
                                {
                                    startplace &&  <Text className='b_logistics__text'>{startplace}</Text>
                                }
                            </View>
                            <View className='b_logistics__item_endplace'>
                                <Text className='b_logistics__title'>目的地址</Text>
                                {
                                  endplace && <Text className='b_logistics__text'>{endplace}</Text>
                                }
                            </View>
                            <View className='b_logistics__item_time'>
                                <Text className='b_logistics__title'>发车日期</Text>
                                {
                                    time && <Text className='b_logistics__text'>{time}</Text>
                                }
                            </View>
                            <View className='b_logistics__item_money'>
                                <Text className='b_logistics__title'>预估价格</Text>
                                {
                                    money && <Text className='b_logistics__text'>{money}</Text>
                                }
                            </View>
                            <View className='b_logistics__item_footer'>
                                <View className='b_logistics__item_footer__left'>
                                    {
                                        total && <Text className='b_logistics__item_footer__left_text'>共托运 {total} 台</Text>
                                    }
                                    {
                                        summoney && <Text className='b_logistics__item_footer__left_money'>¥ {summoney}</Text>
                                    }
                                </View>
                                
                            </View>
                            <View className='b_logistics__item_btn'>
                                    {
                                        firstText && <AtButton className='item_btn item_btn__default' onClick={this.onHanldeFirst.bind(this)}>{firstText}</AtButton>
                                    }
                                    {
                                        secodeText && <AtButton className='item_btn item_btn__default' onClick={this.onHanldeSecode.bind(this)}>{secodeText}</AtButton>
                                    }
                            </View>
                        </View>
                    // })
                }
            </View>
        )
    }
}

DLogistics.defaultProps = {
    className: '',
    startplace:'',
    endplace:'',
    time:'',
    total:'',
    money:'',
    summoney:'',
    firstText: '',
    secodeText: '',
    handleDetail: () => { },
    onHanldeFirst: () => { },
    onHanldeSecode: () => { }
}
DLogistics.PropsType = {
    className: PropsType.oneOfType[PropsType.string, PropsType.object],
    startplace:PropsType.string,
    endplace:PropsType.string,
    time:PropsType.string,
    money:PropsType.string,
    total:PropsType.string,
    summoney:PropsType.string,
    firstText: PropsType.string,
    secodeText: PropsType.string,
    handleDetail: PropsType.func,
    onHanldeFirst: PropsType.func,
    onHanldeSecode: PropsType.func
}
